package news.web;


import ch.qos.logback.core.util.SystemInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import news.model.CommonResult;
import news.model.Link;
import news.model.News;
import news.model.NewsType;
import news.service.FrontService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "前台管理")
@RequestMapping("/frontApi/frontCtl")
@RestController
public class FrontController {

    @Autowired
    private FrontService frontService;

    /**
     * 查询新闻类型
     * @return
     */
    @ApiOperation(value = "前台查询新闻类型")
    @GetMapping("/newsTypes")
    public CommonResult newsType(){
        List<NewsType> list = frontService.findNewsType();
        return new CommonResult(200,list,"前台查询新闻类型成功");
    }

    /**
     * 查询链接类型
     * @return
     */
    @ApiOperation(value = "前台查询链接")
    @GetMapping("/links")
    public CommonResult links(){
        List<Link> list = frontService.findLinks();
        return new CommonResult(200,list,"查询链接成功");
    }

    /**
     * 查询最新得20条数据
     * @return
     */
    @ApiOperation(value = "查询最新发布的20条新闻")
    @GetMapping("/topNews")
    public CommonResult topNews(){
        List<News> list = frontService.topNews();
        return new CommonResult(200,list,"查询前20条数据");
    }

    @ApiOperation(value = "前台根据类型ID查询新闻")
    @GetMapping("/findNewsByTypeId")
    public CommonResult findNewsByTypeId(Integer typeid){
        List<News> list = frontService.findNewsByTypeId(typeid);
        return new CommonResult(200,list,"查询前20条数据");
    }

    @ApiOperation(value = "前台根据ID查询新闻")
    @GetMapping("/findNewsById")
    public CommonResult findNewsById(Integer newsid){
        News news = frontService.findNewsById(newsid);
        return new CommonResult(200,news,"查询新闻得详细信息");
    }

    /**
     * 在前台显示得系统信息
     * @return
     */
    @ApiOperation(value = "前台查询系统信息")
    @GetMapping("/systeminfo")
    public CommonResult systeminfo(){
        SystemInfo systemInfo = frontService.findsysteminfo();
        return new CommonResult(200,systemInfo,"查询公司信息成功");
    }

    @ApiOperation(value = "前台查询用户头像地址")
    @PostMapping("/selectUrl")
    public CommonResult selectUrl(String nickname){
        String url = frontService.selectUrl(nickname);
        return new CommonResult(200,url,"用户头像地址查询成功");
    }


}
